home *** CD-ROM | disk | FTP | other *** search
- program TstCRC;
-
- {$IFDEF Win32}
- {$APPTYPE CONSOLE}
- {$ENDIF}
-
- uses
- SysUtils,
- {$IFDEF Windows}
- WinCrt,
- {$ENDIF}
- AACRC in 'AACRC.pas';
-
-
- var
- i : integer;
- CRC16 : TaaCRC16;
- CRC32 : TaaCRC32;
- CRCTbl16 : Taa16BitCRCTable;
-
- CRC16Calc : TaaCRC16Calculator;
- CRC32Calc : TaaCRC32Calculator;
-
- AAL5Cell : array [0..47] of byte;
-
- St : array [0..47] of char;
- begin
- writeln('Testing CRC routines');
- try
- {set up a test message}
- Fillchar(St, sizeof(St), 0);
- StrCopy(St, 'a phrase for which the CRC is wanted');
-
- {calculate the 16-bit CRC with the $1021 polynomial}
- writeln('Standard 16-bit CRC (without extra 16 zero bits)');
- CRC16 := AAGet16BitCRCStd(St, StrLen(St), PolyXMODEMCRC);
- writeln(Format('$%4x', [CRC16]));
- writeln('Standard 16-bit CRC (with extra 16 zero bits)');
- CRC16 := AAGet16BitCRCStd(St, StrLen(St) + 2, PolyXMODEMCRC);
- writeln(Format('$%4x', [CRC16]));
-
- {calculate the 16-bit CRC table}
- AACalc16BitCRCTable(CRCTbl16, PolyXMODEMCRC);
-
- {calculate the 16-bit CRC with this table}
- writeln('Standard 16-bit CRC using table');
- CRC16 := AAGet16BitCRCTbl(St, StrLen(St), CRCTbl16);
- writeln(Format('$%4x', [CRC16]));
-
- readln;
-
- writeln('Testing 16-bit CRC class');
- CRC16Calc := TaaCRC16Calculator.Create(PolyXMODEMCRC, false, 0, false);
- try
- writeln('..optimized bit by bit method');
- CRC16 := CRC16Calc.GetCRCStd(St, StrLen(St));
- writeln(Format('$%4x', [CRC16]));
-
- writeln('..table method');
- CRC16 := CRC16Calc.GetCRC(St, StrLen(St));
- writeln(Format('$%4x', [CRC16]));
-
- writeln('..byte by byte method');
- CRC16 := 0;
- for i := 0 to pred(StrLen(St)) do
- CRC16 := CRC16Calc.UpdateCRC(ord(St[i]), CRC16);
- writeln(Format('$%4x', [CRC16]));
-
- writeln('..saving to include file test16.inc');
- CRC16Calc.SaveToIncFile('test16.inc');
- finally
- CRC16Calc.Free;
- end;
- readln;
-
- writeln('Testing 32-bit CRC class with CRC32 method');
- CRC32Calc := TaaCRC32Calculator.Create(PolyCRC32, true, $FFFFFFFF, true);
- try
- writeln('..optimized bit by bit method');
- CRC32 := CRC32Calc.GetCRCStd(St, StrLen(St));
- writeln(Format('$%8x', [CRC32]));
-
- writeln('..table method');
- CRC32 := CRC32Calc.GetCRC(St, StrLen(St));
- writeln(Format('$%8x', [CRC32]));
-
- writeln('..byte by byte method');
- CRC32 := $FFFFFFFF;
- for i := 0 to pred(StrLen(St)) do
- CRC32 := CRC32Calc.UpdateCRC(ord(St[i]), CRC32);
- CRC32 := not CRC32;
- writeln(Format('$%4x', [CRC32]));
-
- writeln('..saving to include file test32.inc');
- CRC32Calc.SaveToIncFile('test32.inc');
- finally
- CRC32Calc.Free;
- end;
- readln;
-
-
- writeln('Testing 32-bit CRC class with standard AAL5 tests, bitbybit method');
- CRC32Calc := TaaCRC32Calculator.Create(PolyAAL5, false, $FFFFFFFF, true);
- try
- writeln('..all zeros: CRC should be $864d7f99');
- fillchar(AAL5Cell, sizeof(AAL5Cell), 0);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRCStd(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
- writeln('..all ones: CRC should be $c55e457a');
- fillchar(AAL5Cell, sizeof(AAL5Cell), $ff);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRCStd(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
- writeln('..sequential from 1: CRC should be $bf671ed0');
- for i := 0 to 39 do
- AAL5Cell[i] := succ(i);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRCStd(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
- finally
- CRC32Calc.Free;
- end;
- readln;
-
- writeln('Testing 32-bit CRC class with standard AAL5 tests, table method');
- CRC32Calc := TaaCRC32Calculator.Create(PolyAAL5, false, $FFFFFFFF, true);
- try
- writeln('..all zeros: CRC should be $864d7f99');
- fillchar(AAL5Cell, sizeof(AAL5Cell), 0);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRC(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
- writeln('..all ones: CRC should be $c55e457a');
- fillchar(AAL5Cell, sizeof(AAL5Cell), $ff);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRC(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
- writeln('..sequential from 1: CRC should be $bf671ed0');
- for i := 0 to 39 do
- AAL5Cell[i] := succ(i);
- AAL5Cell[40] := 0;
- AAL5Cell[41] := 0;
- AAL5Cell[42] := 0;
- AAL5Cell[43] := 40;
- CRC32 := CRC32Calc.GetCRC(AAL5Cell, 44);
- writeln(Format('$%8x', [CRC32]));
-
- writeln('..saving to include file test32a.inc');
- CRC32Calc.SaveToIncFile('test32a.inc');
- finally
- CRC32Calc.Free;
- end;
-
- except
- on E:Exception do
- writeln(E.Message);
- end;
- writeln('Done, press Enter to close');
- readln;
- end.
-